package com.smile.controller;

import cn.dev33.satoken.annotation.SaIgnore;
import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.smile.commons.page.MyBatisPlusPageConverter;
import com.smile.commons.page.R;
import com.smile.model.dto.request.GenerateAirlineFileRequestDTO;
import com.smile.model.dto.request.GetAirportListRequestDTO;
import com.smile.model.dto.request.GetFlightLogRequestDTO;
import com.smile.model.dto.request.GetFlightTaskListRequestDTO;
import com.smile.model.request.*;
import com.smile.model.response.FeisuanFlightLogResponse;
import com.smile.model.response.GenerateAirlineFileResponse;
import com.smile.model.response.GetAirportListResponse;
import com.smile.model.response.GetFlightTaskResponse;
import com.smile.model.response.response.FeisuanFlightLogResponseDTO;
import com.smile.model.response.response.GenerateAirlineFileResponseDTO;
import com.smile.model.response.response.GetAirportListResponseDTO;
import com.smile.model.response.response.GetFlightTaskResponseDTO;
import com.smile.service.AirportService;
import com.smile.service.FlightLogService;
import com.smile.service.FlightTaskProcessService;
import com.smile.service.FlightTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;


@RestController
@RequestMapping("/flightLog")
public class FlightLogController {

    @Autowired
    private FlightTaskProcessService  flightTaskProcessService;


    @Autowired
    private FlightLogService flightLogService;

    @Autowired
    private AirportService airportService;
    @PostMapping("/getAirportList")
    public R<Page<GetAirportListResponse>> getAirportList(@RequestBody GetAirportListRequest getAirportListRequest) {
        GetAirportListRequestDTO getAirportListRequestDTO = new GetAirportListRequestDTO();

        BeanUtil.copyProperties(getAirportListRequest, getAirportListRequestDTO);
        Page<GetAirportListResponseDTO> pages = airportService.getAirportList(getAirportListRequestDTO);

        return R.ok(MyBatisPlusPageConverter.convertPage(pages, GetAirportListResponse.class));
    }


    @PostMapping("/getFlightList")
    public R<Page<GetFlightTaskResponse>> getFlightList(@RequestBody GetFlightTaskListRequest getFlightTaskListRequest) {
        GetFlightTaskListRequestDTO getFlightTaskListRequestDTO = BeanUtil.copyProperties(getFlightTaskListRequest, GetFlightTaskListRequestDTO.class);
        Page<GetFlightTaskResponseDTO> pages = flightTaskProcessService.getFlightTaskList(getFlightTaskListRequestDTO);
        return R.ok(MyBatisPlusPageConverter.convertPage(pages, GetFlightTaskResponse.class));
    }

    @PostMapping("/getFlightLog")
    public R<List<FeisuanFlightLogResponseDTO>> getFlightLog(@RequestBody GetFlightLogRequest getFlightLogRequest) {
        GetFlightLogRequestDTO getFlightLogRequestDTO = new GetFlightLogRequestDTO();

        BeanUtil.copyProperties(getFlightLogRequest, getFlightLogRequestDTO);
        List<FeisuanFlightLogResponseDTO> pages = flightLogService.getFlightLogList(getFlightLogRequestDTO);

        return R.ok(BeanUtil.copyToList(pages, FeisuanFlightLogResponseDTO.class));
    }
}
